package com.taijia.chapter8;

import java.io.*;

/**
 * Created by taijia on 2015/1/31.
 */
public class TestDataStream {
    public static void  main(String[] args) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        DataInputStream dis = null;
        try {
            dos.writeDouble(Math.random());
            dos.writeBoolean(false);
            dos.writeBoolean(true);  // 先写的先读
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            System.out.println(bais.available()); // 还剩多少个字节
            dis = new DataInputStream(bais);
            System.out.println(dis.readDouble());
            System.out.println(dis.readBoolean());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                dos.close();
                if(null != dis)
                    dis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
